package top.as.sean.api.config;

import cn.dev33.satoken.stp.StpInterface;
import cn.hutool.core.util.ObjUtil;
import com.google.common.collect.Lists;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import top.as.sean.biz.system.IUserRole;
import top.as.sean.common.constant.RedisConstant;
import top.as.sean.common.gson.GsonUtil;
import top.as.sean.common.redis.RedisUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * 自定义权限验证接口扩展
 *
 * @author: ArchieSean
 * @create: 2023/2/11
 */
@Component
@RequiredArgsConstructor
public class StpInterfaceImpl implements StpInterface {

    private final IUserRole iUserRole;

    /**
     * 权限列表
     *
     * @param loginId   会话id
     * @param loginType 登录类型
     * @return list
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {

        List<String> list = Lists.newArrayList();
        if (ObjectUtils.isEmpty(loginId)) {
            return list;
        }
        Set<String> btnList = iUserRole.queryBtnList(loginId, null);
        if (CollectionUtils.isEmpty(btnList)) {
            return list;
        }
        list = btnList.stream().filter(ObjUtil::isNotEmpty).collect(Collectors.toList());
        return list;
    }

    /**
     * 角色鉴权暂时不用，根据业务需要更改
     *
     * @param loginId   会话id
     * @param loginType 设备类型
     * @return list
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        return null;
    }
}
